<?php
// +----------------------------------------------------------------------
// | Tpli [ WE ONLY DO WHAT IS NECESSARY ]
// +----------------------------------------------------------------------
// | Author 荒年 < 931274989@qq.com >
// +----------------------------------------------------------------------
// | Explain 管理员表
// +----------------------------------------------------------------------

namespace app\admin\model;
use think\Model;
class Admin extends Model
{
  // public function attachment()
  // {
  //   //关联附件表
  //   return $this->hasOne('Attachment');
  // }
  
  // public static function getAdmin()
  // {

  // }
  public function admincate()
  {
    //关联角色表 一对一 
    return $this->belongsTo('AdminCate','admin_cate_id','id');
  }

  public static function getAdmin($post)
  {
    if (isset($post['keywords']) and !empty($post['keywords'])) {
      $where['nickname'] = ['like', '%' . $post['keywords'] . '%'];
    }
    if (isset($post['admin_cate_id']) and $post['admin_cate_id'] > 0) {
        $where['admin_cate_id'] = $post['admin_cate_id'];
    }
    if(isset($post['create_time']) and !empty($post['create_time'])) {
        $min_time = strtotime($post['create_time']);
        $max_time = $min_time + 24 * 60 * 60;
        $where['create_time'] = [['>=',$min_time],['<=',$max_time]];
    }
    $admin = empty($where) ? self::order('create_time desc')->paginate(20) : self::where($where)->order('create_time desc')->paginate(20,false,['query'=>$post]);
    return $admin;
  }

}
?>